home *** CD-ROM | disk | FTP | other *** search
- /*
- * File IO benchmark
- */
-
- #include "timer.h"
- #define ERROR -1
- #define READERR 0
- #define BEG 0
- #define CURR 1
- #define END 2
- #define READ 0
- #define WRITE 1
- #define UPDATE 2
-
- #define OKCLOSE 0
- #define FILESIZE 650001
- #define COUNT 500
-
- #define C 13849L
- #define A 25173L
- #define ODDNUM 23
-
- long seed=7L;
- long random(), lseek();
- main()
- {
- int i;
- long j,pos;
- int fd;
- char buffer[ODDNUM + 1];
-
- init_timer();
- start_timer();
- if((fd=creat("test.dat",0666)) == ERROR)
- abort("Can't write data file\n");
- else
- printf("File opened for sequential writing\n");
-
- for(j = 0; j < FILESIZE; ++j)
- if(write(fd, "x", 1) == ERROR)
- abort("Unexpected EOF in writing data file\n");
-
- if(close(fd) != OKCLOSE)
- abort("Error closing data file\n");
- else
- printf("Normal termination writing data file\n");
- if((fd = open("test.dat", UPDATE)) == ERROR)
- abort("Can't open data file for random reading and writing\n");
- else
- printf("File opened for random reading and writing\n");
-
- for(i = 0; i < COUNT; ++i)
- {
- j = random(FILESIZE);
- if(j < 0L)
- j = (-j);
- if(FILESIZE - j < ODDNUM)
- continue;
- if((pos = lseek(fd, j, BEG)) == -1L)
- abort("Error seeking to random offset\n");
- if(read(fd, buffer, ODDNUM) == READERR)
- abort("Error reading at random offset\n");
-
- j = random(FILESIZE);
- if(j < 0L)
- j = (-j);
- if(FILESIZE - j < ODDNUM)
- continue;
- if((pos = lseek(fd, j, BEG)) == -1L)
- abort("Error seeking to random offset\n");
- if(write(fd, buffer, ODDNUM) == READERR)
- abort("Error writing at random offset\n");
- }
-
- if(close(fd) != OKCLOSE)
- abort("Error closing data file\n");
- else
- printf("Normal terminations from reading and writing\n");
- print_elapsed("lofile benchmark", REALMIN);
- exit(0);
- }
-
- long random(size)
- long size;
- {
- seed = seed * A+C;
- return (seed % size);
- }
-
- abort(message)
- char *message;
- {
- printf(message);
- exit(ERROR);
- }
-
-